package kaizen;

// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 07/02/2013 04:43:58 p.m.
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   cambioPwd.java

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import kaizen.jdbc.DbAppUnivC;
import kaizen.nomweb.utilerias;

public class cambioPwd extends HttpServlet
{

    public cambioPwd()
    {
    }

    public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws ServletException, IOException
    {
        String s = httpservletrequest.getParameter("txtUsUsuario");
        String s1 = httpservletrequest.getParameter("txtUsPasswordAnt");
        String s2 = httpservletrequest.getParameter("txtUsPasswordNew");
        String s3 = httpservletrequest.getParameter("hidUsCvesis");
        String s4 = utilerias.tomaParametro("dic_sistema", httpservletrequest);
        if(s4 == null)
            s4 = "mocte";
        String s5 = "/kaizen/" + s4 + "Web.properties";
        Properties properties = utilerias.loadProperties(s5);
        String s6 = properties.getProperty("host");
        String s7 = properties.getProperty("plantillas");
        httpservletresponse.setContentType("text/html");
        PrintWriter printwriter = new PrintWriter(httpservletresponse.getOutputStream());
        String s8 = "SELECT US_PASSWD ";
        s8 = s8 + "FROM   gentus ";
        s8 = s8 + "WHERE  US_USUARIO = '" + s + "' ";
        s8 = s8 + "AND    US_PASSWD  = '" + s1 + "' ";
        Vector vector = DbAppUnivC.execQuery(s8);
        if(vector.size() > 0)
        {
            String s9 = "";
            s9 = "UPDATE GENTUS ";
            s9 = s9 + "SET US_PASSWD = '" + s2 + "' ";
            s9 = s9 + "WHERE US_PASSWD = '" + s1 + "' ";
            s9 = s9 + "AND US_USUARIO = '" + s + "' ";
            if(!DbAppUnivC.execStatement(s9))
            {
                String s12 = generaPlantilla("cambioPwd.htm", s6 + s7);
                s12 = replaceString(s12, "<!--comUsCvesis-->", "<input type=\"hidden\" name=\"hidUsCvesis\" value=\"" + s3 + "\">");
                s12 = replaceString(s12, "<!--comError-->", "Error! No existe conexion a la Base de Datos");
                printwriter.println(s12);
            } else
            {
                String s10 = "ALTER USER " + s + " IDENTIFIED BY " + s2;
                DbAppUnivC.execStatement(s10);
                String s13 = generaPlantilla("cambioPwdOk.htm", s6 + s7);
                s13 = replaceString(s13, "<!--comUsuario-->", s);
                s13 = replaceString(s13, "<!--comPassword-->", s2);
                printwriter.println(s13);
            }
        } else
        {
            String s11 = generaPlantilla("cambioPwd.htm", s6 + s7);
            s11 = replaceString(s11, "<!--comError-->", "Error! Algun valor es incorrecto, verifique y capture de nuevo");
            printwriter.println(s11);
        }
        printwriter.close();
    }

    public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws ServletException, IOException
    {
        doGet(httpservletrequest, httpservletresponse);
    }

    public static String generaPlantilla(String s, String s1)
        throws IOException
    {
        String s2 = "";
        try
        {
            URL url = new URL(s1 + s);
            BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(url.openStream()));
            String s3;
            while((s3 = bufferedreader.readLine()) != null) 
                s2 = s2 + s3 + "\n";
            bufferedreader.close();
        }
        catch(MalformedURLException _ex) { }
        return s2;
    }

    public static String replaceString(String s, String s1, String s2)
    {
        String s3 = "-";
        int i = s.indexOf(s1);
        if(i >= 0)
        {
            s3 = s.substring(0, i) + s2;
            s3 = s3 + s.substring(i + s1.length(), s.length());
        } else
        {
            s3 = s;
        }
        return s3;
    }
}